/*!
 * \file	fifo_files.c
 * \brief	fifo files
 * \author	Alexis Lucazeau - lucaze_b@epitech.eu
 * \version	1.0
 * \date	10/24/2010 01:31:31 AM
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>

int     create_fifo_file(char *name, mode_t mode)
{
    int fd;

    unlink(name);
    if (mkfifo(name, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH | S_IWGRP | S_IWOTH) != 0)
    {
        perror("mkfifo");
        exit(EXIT_FAILURE);
    }
    chmod (name, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH | S_IWGRP | S_IWOTH);
    if ((fd = open(name, mode | O_NONBLOCK)) < 0)
    {
        perror("open");
        exit(EXIT_FAILURE);
    }
    return (fd);
}

